<?php
class Zendvn_Systerm_Test extends Zend_Controller_Plugin_Abstract
{

     public function routeStartup(Zend_Controller_Request_Abstract $request){
		//echo '<br>' . __METHOD__;
     }

     public function routeShutdown(Zend_Controller_Request_Abstract $request){
		//echo '<br>' . __METHOD__;
     }
     public function dispatchLoopStartup(){
 		//	echo '<br>' . __METHOD__;
     }
     public function preDispatch(Zend_Controller_Request_Abstract $request){
  		$controller = $this->_request->getParam('controller');
  		$flagAdmin = false;
  		if($controller=='admin'){
  			$flagAdmin = true;
  		}else{
  			$tmp = explode('-',$controller);
  			if($tmp[0]=='admin'){
  				$flagAdmin = true;	
  			}
  		}
      if($flagAdmin == true){
        	
        	$auth = Zend_Auth::getInstance();
        	$flagPage = 'none';
        	if(!$auth->hasIdentity()){
        		$flagPage = 'login';
        	}else{
        		$info = new Zendvn_System_Info();
				$group_acp =  $info->getGroupInfo('group_acp');
        		if($group_acp == 0){
        			$flagPage = 'no-access';
        		}else{
        			$permission = $info->getGroupInfo('permission');
        			if($permission !='Full Access'){
        				$aclInfo = $info->getAclInfo();
        				$acl = new Zendvn_System_Acl($aclInfo);
	        			$arrParam = $this->_request->getParams();
	        			if($acl->isAllowed($arrParam)==false){
	        				$flagPage = 'no-access';
	        			}
        			}
        		}
        	}
  		}
  		if($flagPage!='none'){
	  		if($flagPage == 'login'){
	  			$this->_request->setModuleName('default');
	  			$this->_request->setControllerName('public');
	  			$this->_request->setActionName('login');
	  		}
	     	if($flagPage == 'no-access'){
	  			$this->_request->setModuleName('default');
	  			$this->_request->setControllerName('public');
	  			$this->_request->setActionName('no-access');
	  		}
  		}
  		
  			
     }
	public function postDispatch(Zend_Controller_Request_Abstract $request){
 		//echo '<br>' . __METHOD__;
    }

    public function dispatchLoopShutdown(){
		//echo '<br>' . __METHOD__;
    }
}